#ifndef __IAP_H__
#define __IAP_H__

#include <stdint.h>

/* iap_buffer size. including 2 of command, 2 of packageLen, 4 of operate address, SECTOR_SIZE, 1 of checkSum. */
#define IAP_BUFFER_SIZE                  (SECTOR_SIZE + 12)

typedef enum
{
  iap_ok,
  iap_fail,
  iap_busy,
  iap_verify_data_error,
  iap_unKnowCmd_error,
  iap_check_addr_error,
  iap_check_sum_error,
  iap_erase_sector_error,
  iap_package_size_error,
  iap_program_sector_error,
}iap_status_t;

#include "iap_hw.h"


/* user config. comment the macro definition line to disable related function. */

//#define IAP_DEBUG_ENABLE                                 /**< enable the printf information */
#define CHECK_ADDR                                       /**< check if the address align to the sector start address */
#define CHECK_SUM                                        /**< check the package sum, calculate from the operate address byte */
//#define VERIFY_SECTOR                                    /**< varify the byte after program it */
/* end of user config */


/* user interface */

/**
 * @brief initialize the In-Application-Programming.
 */
void iap_init(void);

/**
 * @brief read the full IAP package with non-blocking.
 */
uint8_t iap_readPackage(uint8_t ch);


/* end of user interface */

void iap_put(uint8_t buff[], uint16_t len);
void iap_puts(uint8_t *str);
#define iap_putchar iap_hw_putchar

#endif
